Back to course home
0% completed
Vote For New Content
Meta Hard Problems
Sliding Window Median (hard)
Solution: Sliding Window Median
Alien Dictionary (hard)
Solution: Alien Dictionary
Minimum Window Substring (hard)
Solution: Minimum Window Substring
Best Meeting Point (hard)
Solution: Best Meeting Point
Maximum Sum of 3 Non-Overlapping Subarrays (hard)
Solution: Maximum Sum of 3 Non-Overlapping Subarrays
Making A Large Island (hard)
Solution: Making A Large Island
Basic Calculator (Hard)
Solution: Basic Calculator
Serialize and Deserialize Binary Tree (hard)
Solution: Serialize and Deserialize Binary Tree
Longest Increasing Path in a Matrix (hard)
Solution: Longest Increasing Path in a Matrix
Valid Palindrome III (hard)
Solution: Valid Palindrome III
Simplify Path (medium)
Problem Statement
Given an absolute file path in a Unix-style file system, simplify it by converting ".." to the previous directory and removing any "." or multiple slashes. The resulting string should represent the shortest absolute path.
Examples
Example 1
- Input: path = "/a//b////c/d//././/.."
- Expected Output: "/a/b/c"
- Explanation:
- Convert multiple slashes (
//) into single slashes (/). "."refers to the current directory and is ignored.".."moves up one directory, so"d"is removed.- The simplified path is
"/a/b/c".
- Convert multiple slashes (
Example 2
- Input: path = "/../"
- Expected Output: "/"
- Explanation:
".."moves up one directory, but we are already at the root ("/"), so nothing happens.- The final simplified path remains
"/".
Example 3
- Input: path = "/home//foo/"
- Expected Output: "/home/foo"
- Explanation:
- Convert multiple slashes (
//) into single slashes (/). - The final simplified path is
"/home/foo".
- Convert multiple slashes (
Constraints:
1 <= path.length <= 3000- path consists of English letters, digits, period '.', slash '/' or '_'.
- path is a valid absolute Unix path.
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Next Permutation
Solution: Simplify Path
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself